﻿Imports System.Numerics
Imports System.Runtime.CompilerServices
Imports BigDecimals.Math
Partial Class BigDecimal
  Shared Widening Operator CType(ByVal x As Integer) As BigDecimal
    Return New BigDecimal(x.ToString)
  End Operator
  Shared Widening Operator CType(ByVal x As Long) As BigDecimal
    Return New BigDecimal(x.ToString)
  End Operator
  Shared Widening Operator CType(ByVal x As Single) As BigDecimal
    If Single.IsNaN(x) Then Throw New InvalidCastException("CTpye: x is NaN")
    If Single.IsPositiveInfinity(x) Then Throw New InvalidCastException("CType: x is PositiveInfinity")
    If Single.IsNegativeInfinity(x) Then Throw New InvalidCastException("CType: y is NegativeInfinity")
    Return New BigDecimal(x.ToString)
  End Operator
  Shared Widening Operator CType(ByVal x As Double) As BigDecimal
    If Double.IsNaN(x) Then Throw New InvalidCastException("CTpye: x is NaN")
    If Double.IsPositiveInfinity(x) Then Throw New InvalidCastException("CType: x is PositiveInfinity")
    If Double.IsNegativeInfinity(x) Then Throw New InvalidCastException("CType: y is NegativeInfinity")
    Return New BigDecimal(x.ToString)
  End Operator
End Class

